<div id="result">
    <h5>Global <?php
if ($this->data['brand_type'] == "style")
    echo _('Styles'); elseif ($this->data['brand_type'] == "condition")
    echo _('Conditions'); else
    echo _('Brands');
?></h5>
    <form method="post" id="brandsettings"  name="brandsettings" action="<?php echo Configure::read('base_url') . "global_brand/index/" . $this->data['brand_type']; ?>">
        <?php if (isset($this->data['brand_settings']['Brandsetting']['prompt'])): ?>
            <input type="hidden" value="<?php echo $this->data['brand_settings']['Brandsetting']['id']; ?>"  name="data[id]" />
<?php endif; ?>
        <table width="100%" cellspacing="0">
            <tbody>		 
                <tr>
                    <td width="1%" class="alt"><input type="checkbox" value="<?php echo $this->data['brand_type']; ?>" <?php if (isset($this->data['brand_settings']['Brandsetting']['prompt'])): ?> checked="checked"<?php endif; ?> name="data[brand_type]" id="suggest_global" /></td>
                    <td class="alt">Suggest global <?php
                        if ($this->data['brand_type'] == "style")
                            echo _('Styles'); elseif ($this->data['brand_type'] == "condition")
                            echo _('Conditions'); else
                            echo _('Brands');
?> for Categories
                    </td>
                    <td class="alt"><div id="loader" style="display:none;"><img src="<?php echo Configure::read('base_url'); ?>img/loading.gif" alt="loading..." /></div></td>
                </tr>
            </tbody>
        </table>	

        <table width="100%" cellspacing="0"  id="suggest_global_content">
            <tbody>		 
                <tr>
                    <td colspan="3">Prompt suggestion:</td>
                </tr>
                <tr>
                    <td width="1%" class="alt"><input name="data[prompt]" type="radio" value="0"<?php if ($this->data['brand_settings']['Brandsetting']['prompt'] == '0'): ?> checked="checked"<?php endif; ?> /></td>
                    <td class="alt">Once, when a new category is created</td>
                    <td class="alt">&nbsp;</td>
                </tr>
                <tr>
                    <td class="alt"><input name="data[prompt]" type="radio"  value="1" <?php if ($this->data['brand_settings']['Brandsetting']['prompt'] == '1'): ?> checked="checked"<?php endif; ?>/></td>
                    <td class="alt">Always, when a category is created or existing is edited</td>
                    <td class="alt"><input type="submit" style="background:#73AE0B; color:#fff; font-size:14px;" name="update" id="update" value="Save" /></td>
                </tr>
                <tr>
                  <!-- <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>  -->
                    <td colspan="3">
                        <div class="brandLetter">
                            <div class="listLetters">
                                <div class="letters">
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="A" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);">A</a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="B" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>B</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="C" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>C</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="D" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>D</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="E" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>E</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="F" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>F</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="G" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>G</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="H" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>H</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="I" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>I</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="J" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>J</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="K" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>K</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="L" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>L</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="M" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>M</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="N" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>N</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="O" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>O</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="P" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>P</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="Q" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>Q</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="R" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>R</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="S" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>S</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="T" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>T</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="U" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>U</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="V" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>V</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="W" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>W</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="X" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>X</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="Y" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>Y</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="Z" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>Z</b></a>
                                    <a onclick="showPop(this)" ElmID="<?php echo $this->data['brand_type']; ?>" ElmID2="123" action="index" controller="global_brand" title="Global Brand" href="javascript:void(0);"><b>1, 2, 3</b></a>

                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>

    <div class="div_header1">Global <?php
                        if ($this->data['brand_type'] == "style")
                            echo _('Styles'); elseif ($this->data['brand_type'] == "condition")
                            echo _('Conditions'); else
                            echo _('Brands');
?></div>
    <form method="post" id="global_brand"  name="global_brand" action="<?php echo Configure::read('base_url') . "global_brand/add/"; ?>">
        <br style="clear:both;">
        <table width="100%" cellspacing="0" id="brandstable">
            <?php if (empty($this->data['global_brand'])): ?>
                <tr>
                    <td><p>No records found with this tag</p></td>
                </tr>
            <?php endif; ?>
            <?php
            $i = 0;
            foreach ($this->data['global_brand'] as $brand):
                $class = null;
                if ($i++ % 2 == 0)
                    $class = ' class="alt"';
                ?> 
                <tr>
                    <td width="88" <?php echo $class; ?>><?php echo $brand['Brand']['id']; ?></td>
                    <td width="92" <?php echo $class; ?>><span id="inputbox_<?php echo $brand['Brand']['id']; ?>"><?php echo $brand['Brand']['brand_description']; ?></span></td>
                    <td width="90" <?php echo $class; ?>><span id="savebutton_<?php echo $brand['Brand']['id']; ?>">
                            <a href="javascript:void(0);" class="clickToEdit" title="Click here to edit <?php echo $brand['Brand']['brand_description']; ?>" entryID="<?php echo $brand['Brand']['id']; ?>">Edit</a>
                            |		
                            <a href="javascript:void(0);" onclick="return showPop(this);" controller="global_brand" action="delete" title="Delete" ElmID="<?php echo $brand['Brand']['id']; ?>" ElmID2="<?php echo $this->data['brand_type']; ?>">Delete</a>
                        </span>
                        <span id="showsave_<?php echo $brand['Brand']['id']; ?>"></span>
                    </td>
                </tr>
<?php endforeach; ?>
        </table> 
        <br />
<?php echo $this->Session->flash(); ?>

        <table width="100%" id="add_global_form" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td class="alt" width="144">					
                    <input type="hidden" name="data[Brand][brand_type]" value="<?php echo $this->data['brand_type']; ?>">
                    <input type="index" id='description' name="data[Brand][brand_description]" size="30" value="Enter global <?php echo $this->data['brand_type']; ?> here" class="required" title="Enter global <?php echo $this->data['brand_type']; ?> here" onblur="if(this.value=='') this.value='Enter global <?php echo $this->data['brand_type']; ?> here'" onfocus="if(this.value=='Enter global <?php echo $this->data['brand_type']; ?> here') this.value='';"/>
                </td>
                <td width="347" class="alt"><input type="submit" style="background:#73AE0B; color:#fff; font-size:14px;" name="Save" id="Save" value="Save" /></td>
            </tr>
        </table>
        <div class="div_bottom1"></div>
    </form>
</div>
<?php echo $html->script(array("jquery.min.js", "jquery.form.js", "jquery.validate.js", "jquery.pagination.js", "jquery.tablesorter.min.js", "jquery.tablednd.js")); ?>	 
<script type="text/javascript">  
    jQuery(document).ready(function(){
        jQuery("#category_table").tablesorter({headers: { 2:{sorter: false},3:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}}}); 
 
        var v = jQuery("#global_brand").validate({
            submitHandler: function(form) {
                jQuery(form).ajaxSubmit({
                    target: "#result"
                });
            }
        });
        var v2 = jQuery("#brandsettings").validate({					
            submitHandler: function(form) {
                jQuery("#loader").show().fadeIn("slow");
                jQuery(form).ajaxSubmit({
                    target: "#result"
                });
            }
        });
		
			
        jQuery("form#global_brand a.clickToEdit").click(function()				
        {
            if(jQuery(this).attr('class')=='clickToEdit'){
                var entryID=(jQuery(this).attr("entryID"));			
                var inputValue=jQuery("#inputbox_"+entryID).html();	
				
                var inputbox='<input type="hidden" value="'+entryID+'" name="data[Brand][id]"><input type="text" id="editbox_'+entryID+'" value="'+inputValue+'" name="data[Brand][brand_description]"><input type="hidden" value="'+inputValue+'" name="old_description" />';
                jQuery("#inputbox_"+entryID).html(inputbox);
				
                var savebutton='<a href="javascript:void(0);" entryID="'+entryID+'" title="Save" onclick="return saveEntry(this);">Save</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:void(0);" entryID="'+entryID+'" onclick="cancelForm(this)">Cancel</a>';
                jQuery("span#savebutton_"+entryID).hide().fadeOut("slow");		
                jQuery("span#showsave_"+entryID).live("click", cancelForm).html(savebutton);	
                jQuery('.required').attr('disabled',true);
                jQuery('#Save').attr('disabled',true);
				
                jQuery("form#global_brand a.clickToEdit").each(function (index,domEle) {
                    jQuery(domEle).removeClass("clickToEdit"); 
                    jQuery(domEle).addClass("clickToCancel"); 
                });
            } else{
                return false;
            }			
			
        });
		
    });
	
    //Global brands/Styles/Conditions edit functions
    function saveEntry(param){		
        data = jQuery("#global_brand").serialize();		
        jQuery.ajax({
            type: 'POST',
            url: baseurl+"global_brand/edit/",
            data: data,
            dataType: 'json',
            success: function(data){
                if(data.message=="Duplicate")
                {
                    alert(data.brandName+" Duplicate entry, please use different");
                }
                else if(data.message=="Yes"){					
                    jQuery('#inputbox_'+data.boxID).html(data.brandName);
                    jQuery('input[name="old_description"]').val(data.brandName);	
                    return false;
                }
                else{										
                    return false;
                }
            }			
        });		
        cancelForm(param);	
        return false;		
    }	
	
    function cancelForm(param){		
        var entryID=(jQuery(param).attr("entryID"));
        var boxID="editbox_"+entryID;
        var inputValue=jQuery('input[name="old_description"]').val();	
        jQuery("#inputbox_"+entryID).html(inputValue);
        jQuery("span#savebutton_"+entryID).show().fadeIn("slow");		
        jQuery("span#savebutton_"+entryID+" a").attr("class","clickToEdit");		
        jQuery("span#showsave_"+entryID).die("click", cancelForm).text("");
		
        jQuery("form#global_brand a.clickToCancel").each(function (index,domEle) {
            jQuery(domEle).removeClass("clickToCancel"); 
            jQuery(domEle).addClass("clickToEdit");
        });
				  
        jQuery('.required').removeAttr('disabled');
        jQuery('#Save').removeAttr('disabled');
    }
	
    var i=1;
    var trs=jQuery("#brandstable tr");
    var length=trs.length;

    function moreItem(){
        trs.show();
        trs.each(function(index){
            if(index > i*14 && index < length){
                jQuery(this).hide();
            }

        });
        i++;
        menuHide(parseInt(jQuery("#brandstable tr:hidden").length));
    }
    function lessItem(){
        i=i-2;
        moreItem();
        menuHide(parseInt(jQuery("#brandstable tr:hidden").length));
    }

    function menuHide(hiddenFields){
        diff=parseInt(length)-hiddenFields;
        if(diff<=15){
            jQuery(".less").hide();
            jQuery(".more").show();
            jQuery(".pipe").hide();
        }

        if(hiddenFields==0){
            jQuery(".less").show();
            jQuery(".more").hide();
            jQuery(".pipe").hide();
        }

        if(diff > 15 && hiddenFields > 0){
            jQuery(".less").show();
            jQuery(".more").show();
            jQuery(".pipe").show();
        }
    }
    
    if(length >= 15){
        jQuery("#brandstable").append('<tr><td></td><td></td><td style="text-align: right;"><a onclick="lessItem()" class="less"> << Less</a><span class="pipe"> || </span><a onclick="moreItem()" class="more">More >></a></td></tr>');
    }
        
    if(jQuery("#brandstable tr:first td").length > 1){
        moreItem();
    }
</script>
<style type="text/css">
    .more, .less{cursor: pointer;}
</style>
<?php //echo $this->element('sql_dump'); ?>